local skel = fk.CreateSkill {
  name = "lb_zero__chehua",
}

Fk:loadTranslationTable {
  ["lb_zero__chehua"] = "掣华",
  [":lb_zero__chehua"] = "每回合限三次，当你使用单目标伤害牌时，你可额外指定攻击范围内所有其他角色为目标，若对所有目标均造成伤害，你摸剩余次数张牌。",

  ["#lb_zero__chehua"] = "掣华：你可以指定攻击范围内所有其他角色为 %arg 的额外目标",

  ["$lb_zero__chehua1"] = "击破！",
  ["$lb_zero__chehua2"] = "肃清！",
}

skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  times = function (self, player)
    return 3 - player:usedSkillTimes(skel.name)
  end,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and player == target and player:usedSkillTimes(skel.name) < 3
        and data.card.is_damage_card and not data.card.multiple_targets
        and table.find(data:getExtraTargets(), function(to)
          return to ~= player and player:inMyAttackRange(to)
        end)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player,
      { skill_name = skel.name, prompt = "#lb_zero__chehua:::" .. data.card:toLogString() })
  end,
  on_use = function(self, event, target, player, data)
    local tos = table.filter(data:getExtraTargets(), function(to)
      return to ~= player and player:inMyAttackRange(to)
    end)
    for _, to in ipairs(tos) do
      data:addTarget(to)
    end
    data.extra_data = data.extra_data or {}
    data.extra_data.lb_zero__chehua = player
  end,
})

skel:addEffect(fk.CardUseFinished, {
  is_delay_effect = true,
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:isAlive() and data.extra_data and data.extra_data.lb_zero__chehua
        and data.extra_data.lb_zero__chehua == player and player:usedSkillTimes(skel.name) < 3
        and data.damageDealt and not table.find(data.tos, function(to)
          return data.damageDealt[to] == nil
        end)
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(3 - player:usedSkillTimes(skel.name), skel.name)
  end,
})

return skel
